import React from 'react';
import PropTypes from 'prop-types';
import {Card, Button, Row, Col, Form, Spin, Table, Popconfirm, message as msg, Collapse} from 'antd';
import routes from './routes';
import {updateValidator} from './validator';
import Return from '../common/Return';
import {FORM_OPTIONS, TABLE, FIXED_COLUMN_WIDTH} from '../constants';
import {getDetail, updateData} from './api';
import {agentKind, currency, saleOrderPriceTerms, saleOrderType, saleOrderTransportType, paymentType} from '../Enum';
import styles from './style.css';
import {conventEnumValueToString} from '../utils';
import WrappedSelect from '../common/WrappedSelect';
import {uuid} from './utils';
import WrappedDatePicker from '../common/WrappedDatePicker';
import {injectIntl, language} from './intl';
import TextInput from 'Shared/components/TextInput';
import WrappedInputNumber from '../common/WrappedInputNumber';
import InputPercent from '../common/InputPercent';
const FormItem = Form.Item;
const {Panel} = Collapse;
const currencyList = currency.toList(language);
const priceClauseList = saleOrderPriceTerms.toList(language);
export class UpdatePanel extends React.PureComponent {
    state = {
        isValidate: false,
        hasOperat: false,
        loading: false,
        detailId: '',
        data: {},
        dealerSaleInformationDetails: [],
    }
   
    componentDidMount() {
        if(this.props.id)
            this.getDetailInfo();
    }
    componentWillUnmount() {
        this.isunmount = true;
    }
    getDetailInfo = () => {
        const id = this.props.id;
        this.setState({loading: true});
        getDetail(id)
            .then(res => {
                if(res.ok)
                    this.setState({
                        loading: false,
                        data: res.data,
                        dealerSaleInformationDetails: res.data.dealerSaleInformationDetails || [],
                    });
                else
                    this.setState(({
                        loading: false
                    }));
            });
    }
    onSubmit = () => {
        this.setState({
            loading: true
        });
        const {data, dealerSaleInformationDetails} = this.state;
        const condition = {
            rowVersion: data.rowVersion,
            dealerSaleInformationDetails: (dealerSaleInformationDetails || []).map(v => ({
                brandId: v.brandId,
                tradeMethodId: v.tradeMethodId,
                kdPackingAttribute: v.kdPackingAttribute,
                pdiExpenseStandard: v.pdiExpenseStandard,
                kdIntervalDate: v.kdIntervalDate,
                priceClause: v.priceClause,
                currency: v.currency,
                remark: v.remark,
                effectiveDate: v.effectiveDate,
                expirationDate: v.expirationDate,
                orderType: v.orderType,
                transportType: v.transportType,
                paymentType: v.paymentType,
                account: v.account,
                carrierId: v.carrierId,
                shippingPortId: v.shippingPortId,
                destinationPort: v.destinationPort,
                deliveryDate: v.deliveryDate,
                theoreticalStoreSaleRatio: v.theoreticalStoreSaleRatio,
                deliveryPlanDeliveryCycleMonth: v.deliveryPlanDeliveryCycleMonth,
                receiveDeliveryCycleMonth: v.receiveDeliveryCycleMonth,
                inTransitDeliveryCycleMonth: v.inTransitDeliveryCycleMonth,
            })),
        };

        const isValid = updateValidator(condition);
        if(!isValid) {
            this.setState({
                isValidate: true,
                loading: false
            });
            return;
        }
        updateData(data.id, condition).then(res => {
            if(res.ok)
                this.props.successReturn();
            if(!this.isunmount)
                this.setState({loading: false});
        });
    }
    onClickReturnBtn = () => {
        this.props.onCancel();
    }
    onClickAddDetailBtn = () => {
        const details = this.state.dealerSaleInformationDetails;
        this.setState({
            dealerSaleInformationDetails: [
                ...details,
                {
                    id: uuid(),
                    isNeedApproved: null
                }
            ],
            hasOperat: true
        });
    };

    onBrandChange = (brandId, id) => {
        const details = this.state.dealerSaleInformationDetails || [];
        const index = details.findIndex(v => v.brandId === brandId);
        if(index === 0)
            return msg.warn(this.props.intl.formatMessage({
                id: 'updatePanel.message.brand',
                defaultMessage: '已存在该品牌'
            }));
        const tmp = details.map(d => {
            const index = details.findIndex(v => v.brandId === brandId);
            if(d.id === id && index === -1)
                return Object.assign({}, d, {
                    brandId,
                });
            return d;
        });
        this.setState({
            dealerSaleInformationDetails: tmp,
            hasOperat: true
        });
    }
    onTradeMethodChange = (tradeMethodId, id) => {
        const details = this.state.dealerSaleInformationDetails || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    tradeMethodId,
                });
            return d;
        });
        this.setState({
            dealerSaleInformationDetails: tmp,
            hasOperat: true
        });
    }
    onCarrierChange = (carrierId, id) => {
        const details = this.state.dealerSaleInformationDetails || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    carrierId,
                });
            return d;
        });
        this.setState({
            dealerSaleInformationDetails: tmp,
            hasOperat: true
        });
    }
    onShippingPortChange = (shippingPortId, id) => {
        const details = this.state.dealerSaleInformationDetails || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    shippingPortId,
                });
            return d;
        });
        this.setState({
            dealerSaleInformationDetails: tmp,
            hasOperat: true
        });
    }
    onDeleteDetail = e => {
        const id = e.target.dataset.id;
        const dealerSaleInformationDetails = this.state.dealerSaleInformationDetails.filter(p => p.id !== id);
        this.setState({
            dealerSaleInformationDetails,
            hasOperat: true
        });
    }
    onDeleteAll = () => {
        this.setState({
            dealerSaleInformationDetails: [],
            hasOperat: true
        });
    }
    onDealerPartInformationChange = (value, name, id) => {
        const details = this.state.dealerSaleInformationDetails || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    [name]: value,
                });
            return d;
        });
        this.setState({
            dealerSaleInformationDetails: tmp,
            hasOperat: true
        });
    }
    render() {
        const {data, dealerSaleInformationDetails, isValidate} = this.state;
        const {formatMessage} = this.props.intl;
        const {brands, tradeMethods, carriers, shippingPorts} = this.props.initEnumData;
        const partInformationColumns = [{
            title: (<span className="ant-form-item-required">{formatMessage({
                id: 'updatePanel.column.brand',
                defaultMessage: '品牌'
            })}</span>
            ),
            width: 150,
            dataIndex: 'brandId',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <WrappedSelect
                            id={record.id}
                            options={brands}
                            value={record.brandId}
                            onChange={this.onBrandChange} />
                    </FormItem>
                );
            }
        }, {
            title: (<span className="ant-form-item-required">{formatMessage({
                id: 'updatePanel.column.tradeMethod',
                defaultMessage: '贸易方式'
            })}</span>
            ),
            width: 150,
            dataIndex: 'tradeMethodId',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <WrappedSelect
                            id={record.id}
                            options={tradeMethods}
                            value={record.tradeMethodId}
                            onChange={this.onTradeMethodChange} />
                    </FormItem>
                );
            }
        }, {
            title: formatMessage({
                id: 'updatePanel.column.priceClause',
                defaultMessage: '价格条款'
            }),
            width: 120,
            dataIndex: 'priceClause',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <WrappedSelect
                            id={record.id}
                            options={priceClauseList}
                            value={record.priceClause}
                            onChange={value => this.onDealerPartInformationChange(value, 'priceClause', record.id)}/>
                    </FormItem>
                );
            }
        }, {
            title: formatMessage({
                id: 'updatePanel.column.currency',
                defaultMessage: '结算币种'
            }),
            width: 120,
            dataIndex: 'currency',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <WrappedSelect
                            id={record.id}
                            options={currencyList}
                            value={record.currency}
                            onChange={value => this.onDealerPartInformationChange(value, 'currency', record.id)}/>
                    </FormItem>
                );
            }
        }, {
            title: formatMessage({
                id: 'updatePanel.column.orderType',
                defaultMessage: '订单类型'
            }),
            width: 120,
            dataIndex: 'orderType',
            render: (text, record) => (
                <FormItem>
                    <WrappedSelect
                        id={record.id}
                        options={saleOrderType.toList(language)}
                        value={record.orderType}
                        onChange={value => this.onDealerPartInformationChange(value, 'orderType', record.id)}/>
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.transportType',
                defaultMessage: '运输方式'
            }),
            width: 120,
            dataIndex: 'transportType',
            render: (text, record) => (
                <FormItem>
                    <WrappedSelect
                        id={record.id}
                        options={saleOrderTransportType.toList(language)}
                        value={record.transportType}
                        onChange={value => this.onDealerPartInformationChange(value, 'transportType', record.id)}/>
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.paymentType',
                defaultMessage: '付款方式'
            }),
            width: 120,
            dataIndex: 'paymentType',
            render: (text, record) => (
                <FormItem>
                    <WrappedSelect
                        id={record.id}
                        options={paymentType.toList(language)}
                        value={record.paymentType}
                        onChange={value => this.onDealerPartInformationChange(value, 'paymentType', record.id)}/>
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.account',
                defaultMessage: '到付账号'
            }),
            dataIndex: 'account',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            name="account"
                            value={record.account}
                            onBlur={value => this.onDealerPartInformationChange(value, 'account', record.id)}/>
                    </FormItem>
                );
            }
        }, {
            title: formatMessage({
                id: 'updatePanel.column.carrier',
                defaultMessage: '货代名称'
            }),
            width: 150,
            dataIndex: 'carrierId',
            render: (text, record) => (
                <FormItem>
                    <WrappedSelect
                        id={record.id}
                        options={carriers}
                        value={record.carrierId}
                        onChange={this.onCarrierChange} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.shippingPort',
                defaultMessage: '发运港口'
            }),
            width: 150,
            dataIndex: 'shippingPortId',
            render: (text, record) => (
                <FormItem>
                    <WrappedSelect
                        id={record.id}
                        options={shippingPorts}
                        value={record.shippingPortId}
                        onChange={this.onShippingPortChange} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.destinationPort',
                defaultMessage: '目的港口'
            }),
            dataIndex: 'destinationPort',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            name="destinationPort"
                            value={record.destinationPort}
                            onBlur={value => this.onDealerPartInformationChange(value, 'destinationPort', record.id)}/>
                    </FormItem>
                );
            }
        }, {
            title: formatMessage({
                id: 'updatePanel.column.deliveryDate',
                defaultMessage: '需求交期'
            }),
            dataIndex: 'deliveryDate',
            render: (text, record) => (
                <FormItem>
                    <WrappedInputNumber
                        min={0}
                        precision={0}
                        name="deliveryDate"
                        value={record.deliveryDate}
                        onBlur={value => this.onDealerPartInformationChange(value, 'deliveryDate', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.theoreticalStoreSaleRatio',
                defaultMessage: '理论总存销比'
            }),
            dataIndex: 'theoreticalStoreSaleRatio',
            render: (text, record) => (
                <FormItem>
                    <InputPercent
                        min={0}
                        precision={4}
                        name="theoreticalStoreSaleRatio"
                        value={record.theoreticalStoreSaleRatio}
                        onBlur={value => this.onDealerPartInformationChange(value, 'theoreticalStoreSaleRatio', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.deliveryPlanDeliveryCycleMonth',
                defaultMessage: '发运计划物流周期月数'
            }),
            dataIndex: 'deliveryPlanDeliveryCycleMonth',
            render: (text, record) => (
                <FormItem>
                    <WrappedInputNumber
                        min={0}
                        precision={0}
                        name="deliveryPlanDeliveryCycleMonth"
                        value={record.deliveryPlanDeliveryCycleMonth}
                        onBlur={value => this.onDealerPartInformationChange(value, 'deliveryPlanDeliveryCycleMonth', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.receiveDeliveryCycleMonth',
                defaultMessage: '新到货物流周期月数'
            }),
            dataIndex: 'receiveDeliveryCycleMonth',
            render: (text, record) => (
                <FormItem>
                    <WrappedInputNumber
                        min={0}
                        precision={0}
                        name="receiveDeliveryCycleMonth"
                        value={record.receiveDeliveryCycleMonth}
                        onBlur={value => this.onDealerPartInformationChange(value, 'receiveDeliveryCycleMonth', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.inTransitDeliveryCycleMonth',
                defaultMessage: '在途物流周期月数'
            }),
            dataIndex: 'inTransitDeliveryCycleMonth',
            render: (text, record) => (
                <FormItem>
                    <WrappedInputNumber
                        min={0}
                        precision={0}
                        name="inTransitDeliveryCycleMonth"
                        value={record.inTransitDeliveryCycleMonth}
                        onBlur={value => this.onDealerPartInformationChange(value, 'inTransitDeliveryCycleMonth', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.kdPackingAttribute',
                defaultMessage: 'KD包装属性'
            }),
            dataIndex: 'kdPackingAttribute',
            render: (text, record) => (
                <FormItem>
                    <TextInput
                        name="kdPackingAttribute"
                        value={record.kdPackingAttribute}
                        onBlur={value => this.onDealerPartInformationChange(value, 'kdPackingAttribute', record.id)}/>
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'updatePanel.column.pdIExpenseStandard',
                defaultMessage: 'PDI费用标准'
            }),
            dataIndex: 'pdiExpenseStandard',
            render: (text, record) => (
                <FormItem>
                    <TextInput
                        name="pdiExpenseStandard"
                        value={record.pdiExpenseStandard}
                        onBlur={value => this.onDealerPartInformationChange(value, 'pdiExpenseStandard', record.id)}/>
                </FormItem>
            )
        }, {
            title: (<span>{formatMessage({
                id: 'updatePanel.column.remark',
                defaultMessage: '备注'
            })}</span>
            ),
            dataIndex: 'remark',
            render: (text, record) => (
                <FormItem>
                    <TextInput
                        name="remark"
                        value={record.remark}
                        onBlur={value => this.onDealerPartInformationChange(value, 'remark', record.id)}/>
                </FormItem>
            )
        }, {
            title: (<span className="ant-form-item-required">{formatMessage({
                id: 'updatePanel.column.effectiveDate',
                defaultMessage: '生效日期'
            })}</span>
            ),
            dataIndex: 'effectiveDate',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <WrappedDatePicker
                            name="effectiveDate"
                            value={record.effectiveDate}
                            onChange={value => this.onDealerPartInformationChange(value, 'effectiveDate', record.id)} />
                    </FormItem>
                );
            }
        }, {
            title: (<span>{formatMessage({
                id: 'updatePanel.column.expirationDate',
                defaultMessage: '失效日期'
            })}</span>
            ),
            dataIndex: 'expirationDate',
            render: (text, record) => (
                <FormItem>
                    <WrappedDatePicker
                        name="expirationDate"
                        value={record.expirationDate}
                        onChange={value => this.onDealerPartInformationChange(value, 'expirationDate', record.id)} />
                </FormItem>
            )
        }, {
            title: dealerSaleInformationDetails && dealerSaleInformationDetails.length > 0
                ? (
                    <Popconfirm placement="topRight" title={formatMessage({
                        id: 'updatePanel.validation.isDelete',
                        defaultMessage: '是否确认全部删除？'
                    })} onConfirm={this.onDeleteAll} >
                        <a>{formatMessage({
                            id: 'updatePanel.validation.clear',
                            defaultMessage: '清空'
                        })}</a>
                    </Popconfirm>
                )
                : null,
            dataIndex: 'id',
            fixed: 'right',
            width: FIXED_COLUMN_WIDTH,
            render: text => <a data-id={text} onClick={this.onDeleteDetail}>{formatMessage({
                id: 'updatePanel.validation.delete',
                defaultMessage: '删除'
            })}</a>
        }];

        return (
            <div>
                <Spin spinning={this.state.loading}>
                    <Collapse className={styles.collapseMarginTop}>
                        <Panel header={<Form className="form-standard"><Row>
                            <Col {...FORM_OPTIONS.col}>
                                <FormItem label={formatMessage({
                                    id: 'updatePanel.data.code',
                                    defaultMessage: '编号'
                                })}{...FORM_OPTIONS.item} >
                                    {data.code}
                                </FormItem>
                            </Col>
                            <Col {...FORM_OPTIONS.col}>
                                <FormItem label={formatMessage({
                                    id: 'updatePanel.data.name',
                                    defaultMessage: '名称'
                                })}{...FORM_OPTIONS.item} >
                                    {data.name}
                                </FormItem>
                            </Col>
                            <Col {...FORM_OPTIONS.col}>
                                <FormItem label={formatMessage({
                                    id: 'updatePanel.data.shortCode',
                                    defaultMessage: '简码'
                                })}{...FORM_OPTIONS.item} >
                                    {data.shortCode}
                                </FormItem>
                            </Col></Row></Form>}>
                            <Form className="form-standard">
                                <Row>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.shortName',
                                            defaultMessage: '简称'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.shortName}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.kind',
                                            defaultMessage: '总代分类'
                                        })}{...FORM_OPTIONS.item} >
                                            {conventEnumValueToString(agentKind, data.kind)}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.area',
                                            defaultMessage: '国际区域'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.area}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.country',
                                            defaultMessage: '国家'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.country}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.province',
                                            defaultMessage: '省份'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.province}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.city',
                                            defaultMessage: '城市'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.city}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.contactNumber',
                                            defaultMessage: '联系电话'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.contactNumber}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.fax',
                                            defaultMessage: '传真'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.fax}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.address',
                                            defaultMessage: '联系地址'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.address}
                                        </FormItem>
                                    </Col>
                                    <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'updatePanel.data.zipCode',
                                            defaultMessage: '邮政编码'
                                        })}{...FORM_OPTIONS.item} >
                                            {data.zipCode}
                                        </FormItem>
                                    </Col>
                                </Row>
                            </Form>
                        </Panel>
                    </Collapse>
                    <Form className="form-standard">
                        <Card
                            title={formatMessage({
                                id: 'updatePanel.saleInformationDetail',
                                defaultMessage: '总代整车业务清单'
                            })}>
                            <Button
                                type="dashed"
                                icon="plus"
                                block
                                className={styles.plusBtn}
                                onClick={this.onClickAddDetailBtn}>
                                {formatMessage({
                                    id: 'updatePanel.operation.new',
                                    defaultMessage: '新增'
                                })}
                            </Button>
                            <Table
                                className="white-space-nowrap"
                                columns={partInformationColumns}
                                rowKey="id"
                                pagination={false}
                                dataSource={dealerSaleInformationDetails}
                                {...TABLE} />
                        </Card>
                    </Form>
                    <Card>
                        <Row>
                            <Col className="col-align-right">
                                <Button key="submit"
                                    onClick={this.onSubmit}
                                    type="primary"
                                    loading={this.state.loading}>
                                    {formatMessage({
                                        id: 'addPanel.btn.submit',
                                        defaultMessage: '保存'
                                    })}</Button>
                            </Col>
                        </Row>
                    </Card>
                </Spin>
                <div className="page-toolbar">
                    <Return
                        onConfirm={this.onClickReturnBtn}
                        disabled={this.state.loading}
                        showWarning={this.state.hasOperat} />
                </div>
            </div>
        );
    }
}

UpdatePanel.propTypes = {
    successReturn: PropTypes.func.isRequired,
    onCancel: PropTypes.func.isRequired,
    initEnumData: PropTypes.object,
    intl: PropTypes.object,
};

import {connect} from 'react-redux';
import {tableSearch} from './actions';
import {createSelector} from 'reselect';

const getinitEnumData = createSelector(
    state => state.getIn(['page', 'domainData', 'initData']),
    init => {
        const initData = init.toJS();
        const brands = initData.brands ? initData.brands.map(item => ({
            text: `(${item.code}) ${item.name}`,
            value: item.id
        })) : [];
        const tradeMethods = initData.tradeMethods ? initData.tradeMethods.map(item => ({
            text: `(${item.code}) ${item.name}`,
            value: item.id
        })) : [];
        const carriers = initData.carriers ? initData.carriers.map(item => ({
            text: `(${item.code}) ${item.name}`,
            value: item.id
        })) : [];
        const shippingPorts = initData.shippingPorts ? initData.shippingPorts.map(item => ({
            text: `(${item.code}) ${item.name}`,
            value: item.id
        })) : [];
        return {
            brands,
            tradeMethods,
            carriers,
            shippingPorts
        };
    }
);
const mapStateToProps = (state, props) => ({
    initEnumData: getinitEnumData(state),
    id: props.id,
});

const mapDispatchToProps = (dispatch, props) => ({
    successReturn: () => {
        dispatch(tableSearch());
        props.history.push(routes.query.url());
    },
    onCancel: () => {
        props.history.push(routes.query.url());
    },
});
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(UpdatePanel));
